package com.baicaoyuan.web.controller;


import com.baicaoyuan.web.common.LogUtil;
import com.baicaoyuan.web.common.Status;
import com.baicaoyuan.web.common.annotation.MemberAccess;
import com.baicaoyuan.web.common.exception.StateMessage;
import com.baicaoyuan.web.request.BaseRequest;
import com.baicaoyuan.web.request.br.BStockApplyRequest;
import com.baicaoyuan.web.request.br.BStockPeriodRequest;
import com.baicaoyuan.web.response.StockPeriodResponse;
import com.baicaoyuan.web.service.StockPeriodService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 */
@Api(value = "股东分红Controller", tags = {"股东分红操作接口"})
@RestController
@RequestMapping(value = "/stockPeriod")
public class StockPeriodController {

    @Autowired
    StockPeriodService stockPeriodService;


    @ApiOperation(value = "获取分红信息列表", notes = "", code = 200, produces = "application/json")
    @RequestMapping(value = "/getStockInList", method = RequestMethod.POST)
    @MemberAccess
    @ResponseBody
    public Status getStockInList(@RequestBody BaseRequest request) {
        try {
            List<StockPeriodResponse> sh = this.stockPeriodService.getStockPeriod();
            Status result = new Status(StateMessage.SUCCESS);
            result.setData("stockPeriodList", sh);
            return result;
        } catch (Exception ex) {
            LogUtil.Error("", ex);
            return new Status(StateMessage.FAILED);
        }
    }


    @ApiOperation(value = "股东-分红（token）", notes = "", code = 200, produces = "application/json")
    @RequestMapping(value = "/saveStockPeriod", method = RequestMethod.POST)
    @MemberAccess
    @ResponseBody
    public Status saveStockPeriod(@RequestBody BStockPeriodRequest request) {
        try {
            stockPeriodService.save(request);
            Status result = new Status(StateMessage.SUCCESS);
            return result;
        } catch (Exception ex) {
            LogUtil.Error("", ex);
            return new Status(StateMessage.FAILED);
        }
    }
}
